package com.smartwasser.yunhtgl.apphtgl.presenter;

import com.smartwasser.yunhtgl.apphtgl.bean.UserMessages;
import com.smartwasser.yunhtgl.apphtgl.network.RetrofitApi;
import com.smartwasser.yunhtgl.apphtgl.network.Retrofits;
import com.smartwasser.yunhtgl.apphtgl.view.MPagerView;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class MPagerPresenterImpl implements MPagerPresenter {
    MPagerView mPagerView;

    public MPagerPresenterImpl(MPagerView mPagerView) {
        this.mPagerView = mPagerView;
    }

    @Override
    public void getUserData(String JSESSIONID) {
        Retrofits.getInstance().createReq(RetrofitApi.class).getUserMessages(JSESSIONID).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<UserMessages>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                mPagerView.error();
            }

            @Override
            public void onNext(UserMessages userMessages) {
                mPagerView.success(userMessages);
            }
        });
    }
}
